package com.house.business.controller;

import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.house.business.service.MessageService;
import com.house.business.entity.Message;
import com.house.business.vo.MessageVo;
import org.springframework.web.bind.annotation.RestController;
import com.house.framework.controller.BaseController;

/**
 * <p>
 * 留言表 前端控制器
 * </p>
 *
 * @since 2023-05-09
 */
@Slf4j
@RestController
@RequestMapping("/messageController")
public class MessageController extends BaseController {

    @Autowired
    private MessageService messageService;
    /**
    * 新增留言表
    * @param entity
    * t_message新增数据
    * @return 新增数据id
    */
    @ApiOperation(value = "留言表", notes = "新增留言表")
    @RequestMapping(value = "/addMessage", method = RequestMethod.POST)
    public Object addMessage(@RequestBody Message entity) {
        return messageService.addMessage(entity);
    }

    /**
    * 修改留言表
    * @param entity
    * t_message修改数据
    * @return 修改记录数
    */
    @ApiOperation(value = "留言表", notes = "修改留言表")
    @RequestMapping(value = "/updateMessage", method = RequestMethod.POST)
    public Object updateMessage(@RequestBody Message entity) {
        return messageService.updateMessage(entity);
    }

    /**
    * 取指定ID的留言表数据
    * @param id
    * t_message 主键ID
    * @return 返回实体对象
    * 返回指定id 留言表数据
    */
    @ApiOperation(value = "留言表", notes = "取留言表")
    @RequestMapping(value = "/getMessageById", method = RequestMethod.GET)
    public MessageVo getMessageById(@RequestParam Long id) {
        return messageService.getMessageById(id);
    }

    /**
    * 留言表分页取数
    * @param entityVo
    * t_message 分页取数参数，pageIndex=页码；pageSize=每页记录数；
    * @return
    * 返回分页数据
    */
    @RequestMapping(value = "/getMessageList", method = RequestMethod.POST)
    public IPage<MessageVo> getMessageList(@RequestBody MessageVo entityVo){
        IPage<MessageVo> page = messageService.getMessageList(entityVo);
        return page;
    }

    /**
    * 删除指定ID的留言表数据
    * @param id
    * t_message 主键ID
    */
    @ApiOperation(value = "留言表", notes = "删除留言表")
    @RequestMapping(value = "/deleteMessageById/{id}", method = RequestMethod.GET)
    public void deleteMessageById(@PathVariable("id") Long id) {
         messageService.deleteMessageById(id);
    }

    /**
    * 批量删除指定ID的留言表数据
    * @param ids
    * t_message 主键ID
    */
    @ApiOperation(value = "留言表", notes = "批量删除留言表")
    @RequestMapping(value = "/batchDelete", method = RequestMethod.POST)
    public void batchDelete(@RequestParam Long[] ids) {
        messageService.batchDelete(ids);
    }

}
